package com.donger.auth.exception;

import com.donger.common.core.constant.CommonConstants;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.ser.std.StdSerializer;

import java.io.IOException;

public class BootAuth2ExceptionSerializer extends StdSerializer<BootOauth2Exception> {
    protected BootAuth2ExceptionSerializer() {
        super(BootOauth2Exception.class);
    }

    @Override
    public void serialize(BootOauth2Exception value, JsonGenerator gen, SerializerProvider serializerProvider) throws IOException {
        gen.writeStartObject();
        gen.writeObjectField("code", CommonConstants.FAIL_CODE);
        gen.writeStringField("msg", value.getMessage());
        gen.writeStringField("data", value.getErrorCode());
        gen.writeEndObject();
    }
}
